package com.ophiux.system.controller;

import com.ophiux.common.core.base.Result;
import com.ophiux.common.log.annotation.ExtSysLog;
import com.ophiux.common.security.annotation.Inner;
import com.ophiux.system.model.entity.SysLog;
import com.ophiux.system.service.SysLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.SQLException;

/**
 * @desc:
 * @author: hhl
 * @date：2022/7/19 11:55
 */
@Api(tags = "日志API")
@RequestMapping("/sysLog")
@RestController
public class SysLogController {
    @Autowired
    SysLogService sysLogService;

    @GetMapping("/testLog")
    @ExtSysLog(value = "测试日志hh")
    public Result testLog() {
        long count = sysLogService.count();
        return Result.success(count);
    }

    @GetMapping("/getCountLog")
    public Result getCountLog() {
        long count = sysLogService.count();
        return Result.success(count);
    }

    @PostMapping("/saveLog")
    @ApiOperation("保存日志")
    @Inner(value = false)
    public Result saveLog(@RequestBody SysLog sysLog) {
        sysLogService.saveLog(sysLog);
        return Result.success();
    }

    @PostMapping("/saveLog2")
    public Result saveLog2(@RequestBody SysLog sysLog) throws SQLException {
        boolean save = sysLogService.save(sysLog);
        if (save) {
            return Result.success();
        }
        return Result.fail();
    }

}
